﻿'
' Will Strohl (will.strohl@gmail.com)
' http://www.willstrohl.com
' http://dnntweet.codeplex.com
'
' Copyright (c) 2010, Will Strohl
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this 
' software and associated documentation files (the "Software"), to deal in the Software 
' without restriction, including without limitation the rights to use, copy, modify, 
' merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 
' permit persons to whom the Software is furnished to do so, subject to the following 
' conditions:
'
' The above copyright notice and this permission notice shall be included in all copies 
' or substantial portions of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
' INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
' PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
' HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
' OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
'

Imports DotNetNuke.Services.Exceptions
Imports DotNetNuke.UI.Skins.Skin
Imports System.Web.UI
Imports WillStrohl.Modules.Twitter.TwitterController

Namespace WillStrohl.Modules.Twitter

    Partial Public MustInherit Class EditTwitterView
        Inherits WNSPortalModuleBase

#Region " Private Members "

        Private Const c_AutoCompleteKey As String = "jquery.plugin.autocomplete"
        Private Const c_SizzleCSSKey As String = "jquery.plugin.sizzlecss"
        Private Const c_SelectMenuKey As String = "jquery.plugin.selectmenu"
        Private Const c_jqTransformKey As String = "jquery.plugin.jqtransform"

        Private p_SettingsHandlerPath As String = String.Empty
        Private p_SearchHistoryHandlerPath As String = String.Empty

#End Region

#Region " Public Properties "

        Protected ReadOnly Property SettingsHandlerPath() As String
            Get
                If Not String.IsNullOrEmpty(Me.p_SettingsHandlerPath) Then
                    Return Me.p_SettingsHandlerPath
                End If

                If Request.IsSecureConnection Then
                    Me.p_SettingsHandlerPath = String.Concat("https://", Request.Url.Host, Me.ControlPath, "settings.ashx")
                Else
                    Me.p_SettingsHandlerPath = String.Concat("http://", Request.Url.Host, Me.ControlPath, "settings.ashx")
                End If

                Return Me.p_SettingsHandlerPath
            End Get
        End Property

        Protected ReadOnly Property SearchHistoryHandlerPath() As String
            Get
                If Not String.IsNullOrEmpty(Me.p_SearchHistoryHandlerPath) Then
                    Return Me.p_SearchHistoryHandlerPath
                End If

                If Request.IsSecureConnection Then
                    Me.p_SearchHistoryHandlerPath = String.Concat("https://", Request.Url.Host, Me.ControlPath, "SearchHistory.ashx")
                Else
                    Me.p_SearchHistoryHandlerPath = String.Concat("http://", Request.Url.Host, Me.ControlPath, "SearchHistory.ashx")
                End If

                Return Me.p_SearchHistoryHandlerPath
            End Get
        End Property

#End Region

#Region " Event Handlers "

        Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Try

                Me.BindData()

            Catch exc As Exception ' Module failed to load
                ProcessModuleLoadException(Me, exc, Me.IsEditable)
            End Try
        End Sub

#End Region

#Region " Private Helper Functions "

        Private Sub BindData()

            Me.LocalizeModule()

            Me.ImportPlugins()

        End Sub

        Private Sub ImportPlugins()

            ' load the css on page loads
            Me.Page.Header.Controls.Add(New LiteralControl(String.Format(CSS_TAG_INCLUDE_FORMAT, String.Concat(Me.ControlPath, String.Format("css/{0}/jquery-ui.css", Me.jQueryUITheme)))))


            ' Load the AutoComplete plugin script on every page load
            If Not Page.ClientScript.IsClientScriptBlockRegistered(c_AutoCompleteKey) Then
                Page.ClientScript.RegisterClientScriptBlock(Me.GetType, c_AutoCompleteKey, _
                    String.Format(SCRIPT_TAG_INCLUDE_FORMAT, String.Concat(Me.ControlPath, "js/jquery.autocomplete-min.js")), False)
            End If


            ' Load the SizzleCSS plugin script on every page load
            If Not Page.ClientScript.IsClientScriptBlockRegistered(c_SizzleCSSKey) Then
                Page.ClientScript.RegisterClientScriptBlock(Me.GetType, c_SizzleCSSKey, _
                    String.Format(SCRIPT_TAG_INCLUDE_FORMAT, String.Concat(Me.ControlPath, "js/iphone-style-switches/sizzle.js")), False)
            End If


            ' load the plugin client scripts on every page load
            If Not Me.Page.ClientScript.IsClientScriptBlockRegistered(c_jqTransformKey) Then

                ' UNIFORM
                Me.Page.ClientScript.RegisterClientScriptBlock(Me.GetType, c_jqTransformKey, _
                    String.Format(SCRIPT_TAG_INCLUDE_FORMAT, String.Concat(Me.ControlPath, "js/jqTransform/jquery.jqtransform.js")), False)

            End If

            Me.Page.Header.Controls.Add(New LiteralControl(String.Format(CSS_TAG_INCLUDE_FORMAT, String.Concat(Me.ControlPath, "js/jqTransform/jqtransform.css"))))

        End Sub

        Private Sub LocalizeModule()



        End Sub

        Private Sub SendToDefaultView()
            Response.Redirect(NavigateURL)
        End Sub

        Private Sub HandleException(ByVal exc As Exception)
            LogException(exc)

            ' show the end-user the error if they are either a super user, or in the admin role
            If Me.UserInfo.IsSuperUser Or Me.UserInfo.IsInRole(PortalSettings.AdministratorRoleName) Then
                AddModuleMessage(Me, _
                    String.Concat(exc.Message, "<br />", exc.StackTrace), _
                    Skins.Controls.ModuleMessage.ModuleMessageType.RedError)
            Else
                AddModuleMessage(Me, exc.Message, _
                    Skins.Controls.ModuleMessage.ModuleMessageType.RedError)
            End If
        End Sub

#End Region

    End Class

End Namespace